package org.global;

import lombok.*;
import lombok.experimental.SuperBuilder;
import org.global.utils.Copy;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.UpdateTimestamp;
import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.LastModifiedBy;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;

@Setter
@Getter
@ToString
@SuperBuilder
@MappedSuperclass
@NoArgsConstructor
@AllArgsConstructor
@EntityListeners(AuditingEntityListener.class)
public class GEntity<ID extends Serializable> implements Serializable {
    @Id
    @GenericGenerator(name = "uuid", strategy = "org.hibernate.id.UUIDGenerator")
    @GeneratedValue(generator = "uuid")
    @Column(name = "`id`", length = 36)
    private ID id;

    @CreationTimestamp
    @Temporal(TemporalType.TIMESTAMP)
    @Column(columnDefinition = "DATETIME NOT NULL COMMENT '创建时间'")
    private Date createTime;

    @UpdateTimestamp
    @Temporal(TemporalType.TIMESTAMP)
    @Column(columnDefinition = "DATETIME NOT NULL COMMENT '修改时间'")
    private Date updateTime;

    @Column(columnDefinition = "TINYINT DEFAULT 0 COMMENT '删除标识'")
    private boolean del;

    @CreatedBy
    @Column(columnDefinition = "VARCHAR(40) NOT NULL COMMENT '创建者'", updatable = false)
    private String createBy;

    @LastModifiedBy
    @Column(columnDefinition = "VARCHAR(40) NOT NULL COMMENT '更新者'", updatable = false)
    private String updateBy;
}
